<?php
if( !defined( 'ABSOLUTE_PATH' ) )
    exit('No direct open allowed!');

define( 'SYSTEM_PATH', ABSOLUTE_PATH . 'system/');
define( 'CLASSES_PATH', SYSTEM_PATH . 'classes/' );
define( 'INTERFACES_PATH', SYSTEM_PATH . 'interfaces/' );
define( 'FACTORYS_PATH', SYSTEM_PATH . 'factorys/' );
define( 'PARSERS_PATH', SYSTEM_PATH . 'parsers/' );
define( 'PLUGINS_PATH', SYSTEM_PATH . 'plugins/' );

define( 'APPLICATION_PATH', ABSOLUTE_PATH . 'application/');
define( 'CONFIG_PATH', APPLICATION_PATH . 'configs/' );
define( 'CONTROLLERS_PATH', APPLICATION_PATH . 'controllers/' );
define( 'MODELS_PATH', APPLICATION_PATH . 'models/' );
define( 'VIEWS_PATH', APPLICATION_PATH . 'views/' );
define( 'ERRORS_PATH', APPLICATION_PATH . 'errors/' );
define( 'STATIC_PATH', APPLICATION_PATH . 'static/' );

define( 'URLHOST', $_SERVER['HTTP_HOST'] );
define( 'URLPATH', '/' . trim( dirname($_SERVER['SCRIPT_NAME']), '/' ) . '/' );
define( 'URLSTATIC', URLPATH . 'application/static/' );

include CLASSES_PATH . 'Exception.class' . PHP_EX;
include CLASSES_PATH . 'Config.class' . PHP_EX;
include CLASSES_PATH . 'Reg.class' . PHP_EX;
include CLASSES_PATH . 'Router.class' . PHP_EX;
include CLASSES_PATH . 'Input.class' . PHP_EX;
include CLASSES_PATH . 'Uri.class' . PHP_EX;
include CLASSES_PATH . 'FrontController.class' . PHP_EX;
include CLASSES_PATH . 'Load.class' . PHP_EX;
include CLASSES_PATH . 'Model.class' . PHP_EX;
include CLASSES_PATH . 'Controller.class' . PHP_EX;

include INTERFACES_PATH . 'Parser.interface' . PHP_EX;

include FACTORYS_PATH . 'View.factory' . PHP_EX;

if( Config::get( 'use_database', 'config') ) {
    include CLASSES_PATH . 'Database.class' . PHP_EX;
    
    $db_driver = Config::get( 'driver', 'db_config');
    $connection = Database::factory( $db_driver );
    Reg::set( 'database', $connection );
    
    unset( $db_driver );
}

if( Config::get( 'use_sessions', 'config' ) ) {
    include CLASSES_PATH . 'Session.class' . PHP_EX;
    $session = new Session();
    Reg::set( 'session', $session );
}

$router = new Router();
Input::init( $router );
Uri::init( $router );
FrontController::dispatch( $router );